package com.atguigu.eud_teacher.controller;
import com.atguigu.commonutils.R;
import com.atguigu.eud_teacher.entity.ChapterEntity;
import com.atguigu.eud_teacher.service.ChapterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * 课程
 *
 * @author wuyao
 * @email 13918471632@163.com
 * @date 2021-03-23 12:12:26
 */
@RestController
@RequestMapping("/vue-admin-template/chapter")
@Api(tags = "章节信息管理接口API")
@CrossOrigin
public class ChapterController {

    @Autowired
    private ChapterService chapterService;


    //通过课程基本信息的id获取所有章节和小节
    @ApiOperation(value = "章节小节集合")
    @GetMapping("/getAllChaptersAndVideos/{courseId}")
    public R getAllChaptersAndVideos(@PathVariable String courseId) {
        List<ChapterEntity> chaptersAndVideosList = chapterService.findAllChaptersAndVideos(courseId);
        return R.ok().data("chaptersAndVideosList", chaptersAndVideosList);
    }

    //添加章节
    @ApiOperation(value = "添加章节")
    @PostMapping("/addChapter")
    public R addChapter(@RequestBody ChapterEntity chapterEntity) {
        chapterService.save(chapterEntity);
        return R.ok();
    }

    //通过id查询章节
    @ApiOperation(value = "查询章节")
    @GetMapping("/getChapterById/{id}")
    public R getChapterById(@PathVariable String id) {
        ChapterEntity chapterEntity = chapterService.getById(id);
        return R.ok().data("chapterEntity", chapterEntity);
    }

    //修改章节
    @ApiOperation(value = "修改章节")
    @PostMapping("/updateChapter")
    public R updateChapter(@RequestBody ChapterEntity chapterEntity) {
        chapterService.updateById(chapterEntity);
        return R.ok();
    }

    //删除章节
    @ApiOperation(value = "删除章节")
    @DeleteMapping("/deleteChapter/{id}")
    public R deleteChapter(@PathVariable String id) {
        chapterService.removeChapterAndVideo(id);
        return R.ok();
    }

//    public static void main(String[] args) {
//        List<String> ids=new ArrayList<>();
//        ids.add("111");
//        ids.add("222");
//        System.out.println(StringUtils.join(ids.toArray(),"!!"));
//    }
}

